home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / msql / bind-4.9.3-BETA24.950802.cdiff < prev    next >
Text File  |  1996-10-25  |  29KB  |  1,144 lines

  1. diff -c -r bind-BETA24/Makefile bind-BETA24-msql/Makefile
  2. *** bind-BETA24/Makefile    Fri Jul 07 02:33:32 1995
  3. --- bind-BETA24-msql/Makefile    Fri Jul 21 18:20:19 1995
  4. ***************
  5. *** 75,85 ****
  6.   # DO NOT COMMENT THESE OUT.  OVERRIDE THEM BELOW.
  7.   #
  8.   CC = cc $(CPPFLAGS)
  9. ! CPPFLAGS=
  10.   INDOT =
  11.   XFER_INDOT =
  12.   LEX = lex -I
  13. ! LIBS = -ll -lutil
  14.   PIDDIR = /var/run
  15.   DESTBIN = /usr/bin
  16.   DESTSBIN = /usr/sbin
  17. --- 75,85 ----
  18.   # DO NOT COMMENT THESE OUT.  OVERRIDE THEM BELOW.
  19.   #
  20.   CC = cc $(CPPFLAGS)
  21. ! CPPFLAGS= -I/usr/local/Minerva/include
  22.   INDOT =
  23.   XFER_INDOT =
  24.   LEX = lex -I
  25. ! LIBS = -ll -lutil -L/usr/local/Minerva/lib -lmsql -lmisc
  26.   PIDDIR = /var/run
  27.   DESTBIN = /usr/bin
  28.   DESTSBIN = /usr/sbin
  29. ***************
  30. *** 115,132 ****
  31.   #LEX=lex
  32.   
  33.   #(DEC AXP OSF/1 Version 2.1 and earlier)
  34. ! #CC = cc $(CPPFLAGS) -Olimit 2000
  35. ! #CPPFLAGS =
  36. ! #LEX = lex
  37. ! #LIBS = -ll -lutil
  38. ! #DESTEXEC = /usr/sbin
  39. ! #COMPINCL = compat/include
  40. ! #INSTALL_COMPAT = install-compat
  41. ! #INSTALL = installbsd
  42. ! #MANDIR = man
  43. ! #MANROFF = cat
  44. ! #CATEXT = $$$$N
  45. ! #PS = ps -p
  46.   
  47.   #(DEC AXP OSF/1 Version 3.0 and after)
  48.   #CC = cc $(CPPFLAGS) -std -Olimit 2000
  49. --- 115,132 ----
  50.   #LEX=lex
  51.   
  52.   #(DEC AXP OSF/1 Version 2.1 and earlier)
  53. ! CC = cc $(CPPFLAGS) -Olimit 2000
  54. ! CPPFLAGS = -I/usr/Minerva/include
  55. ! LEX = lex
  56. ! LIBS = -ll -lutil -L/usr/Minerva/lib -lmsql 
  57. ! DESTEXEC = /usr/sbin
  58. ! COMPINCL = compat/include
  59. ! INSTALL_COMPAT = install-compat
  60. ! INSTALL = installbsd
  61. ! MANDIR = man
  62. ! MANROFF = cat
  63. ! CATEXT = $$$$N
  64. ! PS = ps -p
  65.   
  66.   #(DEC AXP OSF/1 Version 3.0 and after)
  67.   #CC = cc $(CPPFLAGS) -std -Olimit 2000
  68. ***************
  69. *** 226,236 ****
  70.   #don't include sys/stream.h via netinet/in.h by defining _SYS_STREAM_H.
  71.   #PIDDIR = /etc
  72.   #LEX = lex
  73. ! #CC = cc $(CPPFLAGS)
  74. ! #CPPFLAGS = -DSVR4 -D_SYS_STREAM_H
  75.   #INDOT = in.
  76.   #XFER_INDOT =
  77. ! #LIBS = -ll -lnsl -lsocket
  78.   #DESTEXEC = /usr/sbin
  79.   #LDS = :
  80.   #RANLIB = :
  81. --- 226,236 ----
  82.   #don't include sys/stream.h via netinet/in.h by defining _SYS_STREAM_H.
  83.   #PIDDIR = /etc
  84.   #LEX = lex
  85. ! #CC = cc $(CPPFLAGS) 
  86. ! #CPPFLAGS = -DSVR4 -D_SYS_STREAM_H -I/usr/local/Minerva/include
  87.   #INDOT = in.
  88.   #XFER_INDOT =
  89. ! #LIBS = -ll -lnsl -lsocket -L/usr/local/Minerva/lib -lmsql
  90.   #DESTEXEC = /usr/sbin
  91.   #LDS = :
  92.   #RANLIB = :
  93. Only in bind-BETA24/BSD: BIND
  94. diff -c -r bind-BETA24/conf/options.h bind-BETA24-msql/conf/options.h
  95. *** bind-BETA24/conf/options.h    Thu Jun 29 04:25:56 1995
  96. --- bind-BETA24-msql/conf/options.h    Tue Aug 01 15:29:33 1995
  97. ***************
  98. *** 73,78 ****
  99. --- 73,79 ----
  100.    *      bg = Benoit Grange of INRIA
  101.    *      ckd = Christopher Davis of Kapor Enterprises
  102.    *      gns = Greg Shapiro of WPI
  103. +  *      cls = Christopher Seawood of Rose-Hulman
  104.    */
  105.   
  106.   #define DEBUG        /* enable -d flag and SIGUSR[12] support (ucb) */
  107. ***************
  108. *** 119,124 ****
  109. --- 120,126 ----
  110.   #define XSTATS        /* extended statistics, syslogged periodically (bg) */
  111.   /*#define BIND_NOTIFY    /* experimental - do not enable in customer products */
  112.   /*#define LOC_RR    /* support for (draft) LOC record parsing (ckd) */
  113. + #define MSQL            /* support for msql-aware bind (cls) */
  114.   
  115.   /*--------------------------------------------*
  116.    * no user-servicable parts beyond this point *
  117. Only in bind-BETA24/doc/bog: file.lst
  118. Only in bind-BETA24/doc/bog: file.psf
  119. diff -c -r bind-BETA24/named/db_defs.h bind-BETA24-msql/named/db_defs.h
  120. *** bind-BETA24/named/db_defs.h    Mon Jun 19 15:55:40 1995
  121. --- bind-BETA24-msql/named/db_defs.h    Thu Jul 20 10:33:26 1995
  122. ***************
  123. *** 96,101 ****
  124. --- 96,104 ----
  125.       int16_t        d_rcode;    /* rcode added for negative caching */
  126.   #endif
  127.       int16_t        d_rcnt;
  128. + #ifdef MSQL
  129. +     int16_t         d_dynamic;      /* 0 = static, 1 = dynamic entry */
  130. + #endif
  131.   #ifdef STATS
  132.       struct nameser    *d_ns;        /* NS from whence this came */
  133.   #endif
  134. diff -c -r bind-BETA24/named/db_load.c bind-BETA24-msql/named/db_load.c
  135. *** bind-BETA24/named/db_load.c    Tue Jul 04 01:35:12 1995
  136. --- bind-BETA24-msql/named/db_load.c    Wed Aug 02 13:39:14 1995
  137. ***************
  138. *** 74,79 ****
  139. --- 74,82 ----
  140.   #include <resolv.h>
  141.   
  142.   #include "named.h"
  143. + #ifdef MSQL
  144. + #include <msql.h>
  145. + #endif
  146.   
  147.   static int        gettoken __P((register FILE *, const char *)),
  148.               getnonblank __P((FILE *, const char *)),
  149. ***************
  150. *** 83,88 ****
  151. --- 86,107 ----
  152.   static int        empty_token = 0;
  153.   int    getnum_error;
  154.   
  155. + #ifdef MSQL
  156. + #define C_MSQL 151
  157. + #define T_MSQL 151
  158. + typedef struct {
  159. +   m_result *result;
  160. +   int      row;
  161. +   char     buffer[1024];
  162. +   int      linePos;
  163. +   int      status;
  164. +  } msqlResultStruct;
  165. + inline int              GETC __P((FILE *)),
  166. +                         UNGETC __P((int, FILE *));
  167. + char                    msqlGetc __P(());
  168. + msqlResultStruct msqlData;
  169. + #endif
  170.   /*
  171.    * Map class and type names to number
  172.    */
  173. ***************
  174. *** 98,103 ****
  175. --- 117,125 ----
  176.   #endif
  177.       { "chaos",    C_CHAOS },
  178.       { "hs",        C_HS },
  179. + #ifdef MSQL
  180. +     { "msql",         C_MSQL },
  181. + #endif
  182.   };
  183.   #define M_CLASS_CNT (sizeof(m_class) / sizeof(struct map))
  184.   
  185. ***************
  186. *** 136,141 ****
  187. --- 158,166 ----
  188.   #ifdef ALLOW_T_UNSPEC
  189.       { "unspec",    T_UNSPEC },
  190.   #endif /* ALLOW_T_UNSPEC */
  191. + #ifdef MSQL
  192. +     { "msql",         T_MSQL },
  193. + #endif
  194.   };
  195.   #define M_TYPE_CNT (sizeof(m_type) / sizeof(struct map))
  196.   
  197. ***************
  198. *** 187,192 ****
  199. --- 212,220 ----
  200.   #ifdef DO_WARN_SERIAL
  201.       u_int32_t serial;
  202.   #endif
  203. + #ifdef MSQL
  204. +      time_t dbupdate, dbrefresh, dbtime=0;
  205. + #endif
  206.   
  207.       errs = 0;
  208.       didinclude = 0;
  209. ***************
  210. *** 443,449 ****
  211.                       multiline = 1;
  212.                   } else {
  213.                       multiline = 0;
  214. !                     ungetc(c, fp);
  215.                   }
  216.   #ifdef DO_WARN_SERIAL
  217.                   serial = zp->z_serial;
  218. --- 471,477 ----
  219.                       multiline = 1;
  220.                   } else {
  221.                       multiline = 0;
  222. !                     UNGETC(c, fp);
  223.                   }
  224.   #ifdef DO_WARN_SERIAL
  225.                   serial = zp->z_serial;
  226. ***************
  227. *** 450,455 ****
  228. --- 478,489 ----
  229.   #endif
  230.                   zp->z_serial = getnum(fp, filename,
  231.                                 GETNUM_SERIAL);
  232. + #ifdef MSQL
  233. +                 if (usingMsql){
  234. +                   gettime(&tt);
  235. +                   zp->z_serial = tt.tv_sec;
  236. +                 };
  237. + #endif
  238.                   if (getnum_error)
  239.                       errs++;
  240.                   n = (u_int32_t) zp->z_serial;
  241. ***************
  242. *** 672,684 ****
  243.                                   cp = buf + (n = strlen(buf));
  244.                   *cp = ' ';
  245.                   cp++;
  246. !                 while ((i = getc(fp), *cp = i, i != EOF)
  247.                                          && *cp != '\n'
  248.                                          && (n < MAXDATA)) {
  249.                                     cp++; n++;
  250.                                   }
  251.                                   if (*cp == '\n') /* leave \n for getword */
  252. !                                     ungetc(*cp, fp);
  253.                                   *cp = '\0';
  254.                   /* now process the whole line */
  255.                   n = loc_aton(buf, (u_char *)data);
  256. --- 706,718 ----
  257.                                   cp = buf + (n = strlen(buf));
  258.                   *cp = ' ';
  259.                   cp++;
  260. !                 while ((i = GETC(fp), *cp = i, i != EOF)
  261.                                          && *cp != '\n'
  262.                                          && (n < MAXDATA)) {
  263.                                     cp++; n++;
  264.                                   }
  265.                                   if (*cp == '\n') /* leave \n for getword */
  266. !                                     UNGETC(*cp, fp);
  267.                                   *cp = '\0';
  268.                   /* now process the whole line */
  269.                   n = loc_aton(buf, (u_char *)data);
  270. ***************
  271. *** 710,716 ****
  272. --- 744,868 ----
  273.                                   }
  274.                                   break;
  275.   #endif /* ALLOW_T_UNSPEC */
  276. + #ifdef MSQL
  277. +                       case T_MSQL:
  278. +                  {
  279. +  /* Read msql-db info (hostname, db name, table name) from data file */
  280. +                   int dbNum, dbnew=0;
  281. +                   int dbZone=0;
  282. +                   char dbname[255], dbhostname[255], dbtable[255], dbzonetable[255];
  283. +                   char dbString[255];
  284. +                   time_t dbrefresh, dbupdate;
  285. +                   m_row dbrow;
  286. +                   
  287. +                   strncpy(dbhostname,buf,255);
  288. +                   if (!getword((char *)buf, sizeof(buf), fp)){
  289. +                     errs++;
  290. +                     continue;
  291. +                   };
  292. +                   strncpy(dbname,buf,255);
  293. +                   if (!getword((char *)buf, sizeof(buf), fp)){
  294. +                     errs++;
  295. +                     continue;
  296. +                   }
  297. +                   strncpy(dbtable,buf,255);
  298. +                   if (!getword((char *)buf, sizeof(buf), fp)){
  299. +                     errs++;
  300. +                     continue;
  301. +                   }
  302. +                   strncpy(dbzonetable,buf,255);
  303. +                   if (!getword((char *)buf, sizeof(buf), fp)){
  304. +                     errs++;
  305. +                     continue;
  306. +                   }
  307. +                   dbupdate = (time_t)atoi(buf);
  308. +                   if (!getword((char *)buf, sizeof(buf), fp)){
  309. +                     errs++;
  310. +                     continue;
  311. +                   }
  312. +                   dbrefresh = (time_t)atoi(buf);
  313. +                   endline(fp);
  314.   
  315. + /* Attempt to connect to the database */
  316. +                   
  317. +                   if (!strcasecmp(dbhostname,"127.0.0.1") ||
  318. +                       !strcasecmp(dbhostname,"localhost"))
  319. +                     dbNum = msqlConnect(NULL);
  320. +                   else
  321. +                     dbNum = msqlConnect(dbhostname);
  322. +                   if (dbNum == -1){
  323. +                     errs++;
  324. +                     syslog(LOG_ERR,msqlErrMsg);
  325. +                     continue;
  326. +                   };
  327. +                   if (msqlSelectDB(dbNum,dbname)==-1){
  328. +                     errs++;
  329. +                     syslog(LOG_ERR,msqlErrMsg);
  330. +                     msqlClose(dbNum);
  331. +                     continue;
  332. +                   };
  333. +                   strcpy(zp->z_dbdtable,dbtable);
  334. +                   strcpy(zp->z_dbhost,dbhostname);
  335. +                   strcpy(zp->z_dbname,dbname);
  336. +                   strcpy(zp->z_dbztable,dbzonetable);
  337. + /* Start retrieving information from the database */
  338. + /* Get the zoneid first */
  339. +                   gettime(&tt);
  340. +                   sprintf(dbString,"select zoneid from %s where name like '%s.%%'",zp->z_dbztable,zp->z_origin);
  341. +                   if (msqlQuery(dbNum,dbString)==-1){
  342. +                     errs++;
  343. +                     syslog(LOG_ERR,msqlErrMsg);
  344. +                     msqlClose(dbNum);
  345. +                     continue;
  346. +                   };
  347. +                   msqlData.result = msqlStoreResult();
  348. + /* Check validity of zone */
  349. +                   if (!(dbZone=msqlNumRows(msqlData.result))){
  350. +                     errs++;
  351. +                     syslog(LOG_ERR,"msql_dns: No zoneid associated with zone %s",zp->z_origin);
  352. +                     msqlClose(dbNum);
  353. +                     continue;
  354. +                   } else if (dbZone > 1){
  355. +                     syslog(LOG_ERR,"db_load: Multiple zoneids found for zone %s, using first one",zp->z_origin);
  356. +                   };
  357. +                   dbrow = msqlFetchRow(msqlData.result);
  358. +                   dbZone = atoi(dbrow[0]);
  359. +                   msqlFreeResult(msqlData.result);
  360. + /* Zone is valid, start retrieving entries */
  361. +                   sprintf(dbString,"select machine, class, type, info, importance, dynamic from %s where importance<3 or assigned_time >%d and zoneid = %d order by importance", zp->z_dbdtable,zp->z_dbtime,dbZone);
  362. +                   if (msqlQuery(dbNum,dbString)==-1){
  363. +                     errs++;
  364. +                     syslog(LOG_ERR,msqlErrMsg);
  365. +                     msqlClose(dbNum);
  366. +                     continue;
  367. +                   };
  368. +                   msqlData.result = msqlStoreResult();
  369. +                   msqlClose(dbNum);
  370. +                   msqlDataSeek(msqlData.result,0);
  371. + /* Check to see if anything besides SOA & NS entries were retrieved */
  372. +                   while ((dbrow=msqlFetchRow(msqlData.result))!=NULL)
  373. +                     if (atoi(dbrow[4])>2)
  374. +                       dbnew++;
  375. +                   msqlDataSeek(msqlData.result,0);
  376. +                       if (dbnew){                    
  377. +                     msqlData.row = 0;
  378. +                     bzero(msqlData.buffer, 
  379. +                       sizeof(msqlData.buffer));
  380. +                     msqlData.linePos = 0;
  381. + /* Default to static entries */        msqlData.status = 0;
  382. +                     usingMsql = 1;
  383. +                   } else
  384. +                     usingMsql = 0;
  385. +                   zp->z_dbtime = tt.tv_sec;
  386. +                   if (!zp->z_dblastupdate)
  387. +                     zp->z_dblastupdate = tt.tv_sec;
  388. +                   zp->z_dbupdate = dbupdate;
  389. +                   zp->z_dbrefresh = dbrefresh;
  390. +                   break;
  391. +                  }
  392. + #endif /* MSQL */
  393.               default:
  394.                   goto err;
  395.               }
  396. ***************
  397. *** 739,744 ****
  398. --- 891,902 ----
  399.               dp->d_flags = dataflags;
  400.               dp->d_cred = DB_C_ZONE;
  401.               dp->d_clev = clev;
  402. + #ifdef MSQL
  403. +             if (usingMsql)
  404. +               dp->d_dynamic = msqlData.status;
  405. +             else
  406. +               dp->d_dynamic = 0;
  407. + #endif
  408.               if ((c = db_update(domain, dp, dp, dbflags,
  409.                          (zp->z_type == Z_CACHE)
  410.                          ? fcachetab
  411. ***************
  412. *** 824,830 ****
  413.       char op[32];
  414.   
  415.       for (;;) {
  416. !         c = getc(fp);
  417.       top:
  418.           switch (c) {
  419.           case EOF:
  420. --- 982,988 ----
  421.       char op[32];
  422.   
  423.       for (;;) {
  424. !         c = GETC(fp);
  425.       top:
  426.           switch (c) {
  427.           case EOF:
  428. ***************
  429. *** 843,849 ****
  430.               return (ERROR);
  431.   
  432.           case ';':
  433. !             while ((c = getc(fp)) != EOF && c != '\n')
  434.                   ;
  435.               goto top;
  436.   
  437. --- 1001,1007 ----
  438.               return (ERROR);
  439.   
  440.           case ';':
  441. !             while ((c = GETC(fp)) != EOF && c != '\n')
  442.                   ;
  443.               goto top;
  444.   
  445. ***************
  446. *** 862,868 ****
  447.               continue;
  448.   
  449.           default:
  450. !             (void) ungetc(c, fp);
  451.               return (DNAME);
  452.           }
  453.       }
  454. --- 1020,1026 ----
  455.               continue;
  456.   
  457.           default:
  458. !             (void) UNGETC(c, fp);
  459.               return (DNAME);
  460.           }
  461.       }
  462. ***************
  463. *** 889,919 ****
  464.       register int c;
  465.   
  466.       empty_token = 0;
  467. !     for (cp = buf; (c = getc(fp)) != EOF; ) {
  468.           if (c == ';') {
  469. !             while ((c = getc(fp)) != EOF && c != '\n')
  470.                   ;
  471.               c = '\n';
  472.           }
  473.           if (c == '\n') {
  474.               if (cp != buf)
  475. !                 ungetc(c, fp);
  476.               else
  477.                   lineno++;
  478.               break;
  479.           }
  480.           if (isspace(c)) {
  481. !             while (isspace(c = getc(fp)) && c != '\n')
  482.                   ;
  483. !             ungetc(c, fp);
  484.               if (cp != buf)        /* Trailing whitespace */
  485.                   break;
  486.               continue;        /* Leading whitespace */
  487.           }
  488.           if (c == '"') {
  489. !             while ((c = getc(fp)) != EOF && c != '"' && c != '\n') {
  490.                   if (c == '\\') {
  491. !                     if ((c = getc(fp)) == EOF)
  492.                           c = '\\';
  493.                       if (c == '\n')
  494.                           lineno++;
  495. --- 1047,1077 ----
  496.       register int c;
  497.   
  498.       empty_token = 0;
  499. !     for (cp = buf; (c = GETC(fp)) != EOF; ) {
  500.           if (c == ';') {
  501. !             while ((c = GETC(fp)) != EOF && c != '\n')
  502.                   ;
  503.               c = '\n';
  504.           }
  505.           if (c == '\n') {
  506.               if (cp != buf)
  507. !                 UNGETC(c, fp);
  508.               else
  509.                   lineno++;
  510.               break;
  511.           }
  512.           if (isspace(c)) {
  513. !             while (isspace(c = GETC(fp)) && c != '\n')
  514.                   ;
  515. !             UNGETC(c, fp);
  516.               if (cp != buf)        /* Trailing whitespace */
  517.                   break;
  518.               continue;        /* Leading whitespace */
  519.           }
  520.           if (c == '"') {
  521. !             while ((c = GETC(fp)) != EOF && c != '"' && c != '\n') {
  522.                   if (c == '\\') {
  523. !                     if ((c = GETC(fp)) == EOF)
  524.                           c = '\\';
  525.                       if (c == '\n')
  526.                           lineno++;
  527. ***************
  528. *** 926,933 ****
  529.                   lineno++;
  530.                   break;
  531.               }
  532. !             if ((c = getc(fp)) != EOF)
  533. !                 ungetc(c, fp);
  534.               if (c == EOF || isspace(c) || c == '\n') {
  535.                   *cp = '\0';
  536.                   return (1);
  537. --- 1084,1091 ----
  538.                   lineno++;
  539.                   break;
  540.               }
  541. !             if ((c = GETC(fp)) != EOF)
  542. !                 UNGETC(c, fp);
  543.               if (c == EOF || isspace(c) || c == '\n') {
  544.                   *cp = '\0';
  545.                   return (1);
  546. ***************
  547. *** 936,942 ****
  548.                   continue;
  549.           }
  550.           if (c == '\\') {
  551. !             if ((c = getc(fp)) == EOF)
  552.                   c = '\\';
  553.               if (c == '\n')
  554.                   lineno++;
  555. --- 1094,1100 ----
  556.                   continue;
  557.           }
  558.           if (c == '\\') {
  559. !             if ((c = GETC(fp)) == EOF)
  560.                   c = '\\';
  561.               if (c == '\n')
  562.                   lineno++;
  563. ***************
  564. *** 990,996 ****
  565.       if (opt & GETNUM_SERIAL)
  566.           allow_dots++;
  567.   #endif
  568. !     for (n = 0; (c = getc(fp)) != EOF; ) {
  569.           if (isspace(c)) {
  570.               if (c == '\n')
  571.                   lineno++;
  572. --- 1148,1154 ----
  573.       if (opt & GETNUM_SERIAL)
  574.           allow_dots++;
  575.   #endif
  576. !     for (n = 0; (c = GETC(fp)) != EOF; ) {
  577.           if (isspace(c)) {
  578.               if (c == '\n')
  579.                   lineno++;
  580. ***************
  581. *** 999,1005 ****
  582.               continue;
  583.           }
  584.           if (c == ';') {
  585. !             while ((c = getc(fp)) != EOF && c != '\n')
  586.                   ;
  587.               if (c == '\n')
  588.                   lineno++;
  589. --- 1157,1163 ----
  590.               continue;
  591.           }
  592.           if (c == ';') {
  593. !             while ((c = GETC(fp)) != EOF && c != '\n')
  594.                   ;
  595.               if (c == '\n')
  596.                   lineno++;
  597. ***************
  598. *** 1011,1017 ****
  599.               continue;
  600.           if (!isdigit(c)) {
  601.               if (c == ')' && seendigit) {
  602. !                 (void) ungetc(c, fp);
  603.                   break;
  604.               }
  605.               if (seendigit && (opt & GETNUM_SCALED) &&
  606. --- 1169,1175 ----
  607.               continue;
  608.           if (!isdigit(c)) {
  609.               if (c == ')' && seendigit) {
  610. !                 (void) UNGETC(c, fp);
  611.                   break;
  612.               }
  613.               if (seendigit && (opt & GETNUM_SCALED) &&
  614. ***************
  615. *** 1080,1086 ****
  616.   {
  617.       register int c;
  618.   
  619. !     while ( (c = getc(fp)) != EOF ) {
  620.           if (isspace(c)) {
  621.               if (c == '\n')
  622.                   lineno++;
  623. --- 1238,1244 ----
  624.   {
  625.       register int c;
  626.   
  627. !     while ( (c = GETC(fp)) != EOF ) {
  628.           if (isspace(c)) {
  629.               if (c == '\n')
  630.                   lineno++;
  631. ***************
  632. *** 1087,1093 ****
  633.               continue;
  634.           }
  635.           if (c == ';') {
  636. !             while ((c = getc(fp)) != EOF && c != '\n')
  637.                   ;
  638.               if (c == '\n')
  639.                   lineno++;
  640. --- 1245,1251 ----
  641.               continue;
  642.           }
  643.           if (c == ';') {
  644. !             while ((c = GETC(fp)) != EOF && c != '\n')
  645.                   ;
  646.               if (c == '\n')
  647.                   lineno++;
  648. ***************
  649. *** 1142,1150 ****
  650.   {
  651.       register int c;
  652.   
  653. !     while ((c = getc(fp)) != '\0') {
  654.           if (c == '\n') {
  655. !             (void) ungetc(c,fp);
  656.               break;
  657.           } else if (c == EOF) {
  658.               break;
  659. --- 1300,1308 ----
  660.   {
  661.       register int c;
  662.   
  663. !     while ((c = GETC(fp)) != '\0') {
  664.           if (c == '\n') {
  665. !             (void) UNGETC(c,fp);
  666.               break;
  667.           } else if (c == EOF) {
  668.               break;
  669. ***************
  670. *** 1201,1207 ****
  671.           }
  672.           if ( b[0] == ')') {
  673.               bracket = 0;
  674. !             while ((ch = getc(fp)) != EOF && ch != '\n')
  675.                   ;
  676.               if (ch == '\n')
  677.                   lineno++;
  678. --- 1359,1365 ----
  679.           }
  680.           if ( b[0] == ')') {
  681.               bracket = 0;
  682. !             while ((ch = GETC(fp)) != EOF && ch != '\n')
  683.                   ;
  684.               if (ch == '\n')
  685.                   lineno++;
  686. ***************
  687. *** 1364,1366 ****
  688. --- 1522,1574 ----
  689.       }
  690.       *netlistp = NULL;
  691.   }
  692. + #ifdef MSQL
  693. + inline int GETC(FILE *fp)
  694. + { 
  695. +   if (usingMsql) 
  696. +     {
  697. +       if (msqlData.buffer[msqlData.linePos] == '\0')
  698. +     return(msqlGetc(&msqlData)); 
  699. +       else
  700. +     return (msqlData.buffer[msqlData.linePos++]);
  701. +     }
  702. +   else     
  703. +     return(getc(fp));
  704. + }
  705. + inline int UNGETC(int c, FILE *fp)
  706. + {
  707. +   if (usingMsql)
  708. +     {
  709. +       if (msqlData.linePos > 0)
  710. +     msqlData.linePos--; 
  711. +       return(c);
  712. +     }
  713. +   else 
  714. +     return(ungetc(c, fp));
  715. + }
  716. + char msqlGetc(msqlResultStruct *s)
  717. + {
  718. +   m_row row;
  719. +   row = msqlFetchRow(s->result);
  720. +   (s->row)++;
  721. +   if (row == NULL)
  722. +     {
  723. +       msqlFreeResult(s->result);
  724. +       usingMsql = 0;
  725. +       return '\n';
  726. +     }
  727. +   bzero(s->buffer, sizeof(s->buffer));
  728. +   (void) sprintf(s->buffer,"%s %s %s %s\n",
  729. +          row[0],row[1],row[2],row[3]);
  730. +   s->linePos = 0;
  731. +   s->status = atoi(row[5]);
  732. +   return (s->buffer[(s->linePos)++]);
  733. + }
  734. + #else
  735. + #define GETC(fp) getc(fp)
  736. + #define UNGETC(c,fp) ungetc(c,fp)
  737. + #endif /* MSQL */
  738. diff -c -r bind-BETA24/named/db_update.c bind-BETA24-msql/named/db_update.c
  739. *** bind-BETA24/named/db_update.c    Thu Jun 29 04:26:19 1995
  740. --- bind-BETA24-msql/named/db_update.c    Wed Aug 02 13:40:37 1995
  741. ***************
  742. *** 521,527 ****
  743.                       !bcmp(dp->d_data, newdp->d_data,
  744.                         INT32SZ + sizeof(u_char)))
  745.                       goto delete;
  746. !             }
  747.               if ((flags & DB_NODATA) && !db_cmp(dp, odp)) {
  748.                   /* refresh ttl if cache entry */
  749.                   if (dp->d_zone == 0) {
  750. --- 521,538 ----
  751.                       !bcmp(dp->d_data, newdp->d_data,
  752.                         INT32SZ + sizeof(u_char)))
  753.                       goto delete;
  754. ! #ifdef MSQL
  755. !                 /* 
  756. !                  *  We don't want multiple ip addresses 
  757. !                  *  returned or inverse lookups going to the 
  758. !                  *  wrong machine for dynamic hosts
  759. !                  */
  760. !                 if (dp->d_dynamic && 
  761. !                     bcmp(dp->d_data, newdp->d_data,
  762. !                      INT32SZ + sizeof(u_char)))
  763. !                   goto delete;
  764. ! #endif /* MSQL */
  765. !              }
  766.               if ((flags & DB_NODATA) && !db_cmp(dp, odp)) {
  767.                   /* refresh ttl if cache entry */
  768.                   if (dp->d_zone == 0) {
  769. diff -c -r bind-BETA24/named/named.h bind-BETA24-msql/named/named.h
  770. *** bind-BETA24/named/named.h    Thu Dec 15 01:24:17 1994
  771. --- bind-BETA24-msql/named/named.h    Mon Jul 10 14:14:49 1995
  772. ***************
  773. *** 17,19 ****
  774. --- 17,20 ----
  775.   
  776.   #include "ns_func.h"
  777.   #include "db_func.h"
  778. diff -c -r bind-BETA24/named/ns_defs.h bind-BETA24-msql/named/ns_defs.h
  779. *** bind-BETA24/named/ns_defs.h    Mon Jun 19 15:55:43 1995
  780. --- bind-BETA24-msql/named/ns_defs.h    Wed Jul 12 11:30:32 1995
  781. ***************
  782. *** 133,138 ****
  783. --- 133,148 ----
  784.       /* XXX - this will have to move to the name when we do !SOA notify */
  785.       struct notify    *z_notifylist;    /* list of servers we should notify */
  786.   #endif
  787. + #ifdef MSQL
  788. +     u_int32_t       z_dbtime;       /* latest modification time of db */
  789. +     u_int32_t       z_dblastupdate; /* last time cache was updated */
  790. +     time_t          z_dbupdate;     /* db cache update rate */
  791. +     time_t          z_dbrefresh;    /* cache refresh rate */
  792. +     char            z_dbhost[255];  /* hostname of db server */
  793. +     char            z_dbname[255];  /* name of db */
  794. +     char            z_dbdtable[255]; /* name of dns table */
  795. +     char            z_dbztable[255];  /* name of zone table */
  796. + #endif
  797.   };
  798.   
  799.   #ifdef BIND_NOTIFY
  800. diff -c -r bind-BETA24/named/ns_glob.h bind-BETA24-msql/named/ns_glob.h
  801. *** bind-BETA24/named/ns_glob.h    Mon Jun 19 15:55:44 1995
  802. --- bind-BETA24-msql/named/ns_glob.h    Mon Jul 10 14:14:50 1995
  803. ***************
  804. *** 265,267 ****
  805. --- 265,272 ----
  806.       /* should IQUERY be answered bogusly rather than with NOTIMPL? */
  807.   DECL    int            fake_iquery    INIT(0);
  808.   #endif
  809. + #ifdef MSQL
  810. +         /* is a msql db being accessed? */
  811. + DECL    int                     usingMsql       INIT(0);
  812. + #endif
  813. diff -c -r bind-BETA24/named/ns_init.c bind-BETA24-msql/named/ns_init.c
  814. *** bind-BETA24/named/ns_init.c    Thu Jun 29 04:26:21 1995
  815. --- bind-BETA24-msql/named/ns_init.c    Thu Jul 20 14:16:11 1995
  816. ***************
  817. *** 73,78 ****
  818. --- 73,81 ----
  819.   #include <assert.h>
  820.   
  821.   #include "named.h"
  822. + #ifdef MSQL
  823. + #include <msql.h>
  824. + #endif
  825.   
  826.   #undef nsaddr
  827.   
  828. ***************
  829. *** 511,516 ****
  830. --- 514,522 ----
  831.                * then there's no need to reload.
  832.                */
  833.               if (zp->z_source &&
  834. + #ifdef MSQL
  835. +                 !msql_update_check(zp) &&
  836. + #endif 
  837.                   !strcmp(source, zp->z_source) &&
  838.                   !(zp->z_flags & Z_INCLUDE) && 
  839.                   stat(zp->z_source, &f_time) != -1 &&
  840. ***************
  841. *** 945,947 ****
  842. --- 951,1030 ----
  843.           exit(1);
  844.       }
  845.   }
  846. +  
  847. + #ifdef MSQL
  848. + /*
  849. +  * Returns
  850. +  * 0 if msql db has NOT changed.
  851. +  * >1 if msql db has changed.
  852. +  */
  853. + extern int 
  854. + msql_update_check (zp)
  855. + struct zoneinfo *zp;
  856. + {
  857. +   
  858. +    int dbNum;
  859. +    m_row dbRow;
  860. +    m_result *dbDNS;
  861. +    char dbString[255];
  862. +    int update=0, dbZone;
  863. +    m_result *dbRes;
  864. +    
  865. + /* Update the cache if db has never been read */
  866. +    if (!strlen(zp->z_dbhost) || 
  867. +        !strlen(zp->z_dbname) || 
  868. +        !strlen(zp->z_dbdtable) ||
  869. +        !strlen(zp->z_dbztable))
  870. +      return 0;
  871. +    if (!strcasecmp(zp->z_dbhost,"127.0.0.1") ||
  872. +        !strcasecmp(zp->z_dbhost,"localhost"))
  873. +      dbNum = msqlConnect(NULL);
  874. +    else
  875. +      dbNum = msqlConnect(zp->z_dbhost);
  876. +    if (dbNum == -1){
  877. +      syslog(LOG_ERR,msqlErrMsg);
  878. +      return 0;
  879. +    };
  880. +     if (msqlSelectDB(dbNum,zp->z_dbname)==-1){
  881. +      syslog(LOG_ERR,msqlErrMsg);
  882. +      msqlClose(dbNum);
  883. +      return 0;
  884. +    };
  885. +    sprintf(dbString,"select zoneid from %s where name like '%s.%%'",zp->z_dbztable,zp->z_origin);
  886. +    if (msqlQuery(dbNum,dbString)==-1){
  887. +      syslog(LOG_ERR,msqlErrMsg);
  888. +      msqlClose(dbNum);
  889. +      return 0;
  890. +    };
  891. +    dbRes = msqlStoreResult();
  892. +    if (!(dbZone=msqlNumRows(dbRes))){
  893. +      syslog(LOG_ERR,"msql_update_check: No zoneid associated with zone %s",zp->z_origin);
  894. +      msqlClose(dbNum);
  895. +      return 0;
  896. +    };
  897. +    dbRow = msqlFetchRow(dbRes);
  898. +    dbZone = atoi(dbRow[0]);
  899. +    sprintf(dbString,"Select assigned_time from %s where zoneid = %d and assigned_time > %d",zp->z_dbdtable,dbZone, zp->z_dbtime);
  900. +    if (msqlQuery(dbNum,dbString)==-1){
  901. +      syslog(LOG_ERR,msqlErrMsg);
  902. +      msqlClose(dbNum);
  903. +      return 0;
  904. +    };
  905. +    dbDNS = msqlStoreResult();   
  906. +    if (msqlNumRows(dbDNS))
  907. +      update++;
  908. +    msqlFreeResult(dbDNS);
  909. + /* Close connection to Msql DB */
  910. +    msqlClose(dbNum);
  911. +   return update;
  912. + };
  913. + #endif /*MSQL*/
  914. diff -c -r bind-BETA24/named/ns_maint.c bind-BETA24-msql/named/ns_maint.c
  915. *** bind-BETA24/named/ns_maint.c    Thu Jun 29 04:26:23 1995
  916. --- bind-BETA24-msql/named/ns_maint.c    Wed Jul 12 11:35:54 1995
  917. ***************
  918. *** 72,77 ****
  919. --- 72,80 ----
  920.   #include <sys/stat.h>
  921.   
  922.   #include "named.h"
  923. + #ifdef MSQL
  924. + #include <msql.h>
  925. + #endif
  926.   
  927.   #ifdef USE_UTIME
  928.   # include <utime.h>
  929. ***************
  930. *** 88,93 ****
  931. --- 91,103 ----
  932.               addxfer __P((struct zoneinfo *)),
  933.               tryxfer __P((void));
  934.   
  935. + #ifdef MSQL
  936. + static void              msql_update_cache __P((void));
  937. + int dbrefresh;
  938. + int dbupdatereload;
  939. + int dbinit;
  940. + #endif 
  941.   #define    qserial_qfull()    (qserials_running == MAXQSERIAL)
  942.   
  943.   #ifdef CLEANCACHE
  944. ***************
  945. *** 100,105 ****
  946. --- 110,116 ----
  947.    * Invoked at regular intervals by signal interrupt; refresh all secondary
  948.    * zones from primary name server and remove old cache entries.  Also,
  949.    * ifdef'd ALLOW_UPDATES, dump database if it has changed since last
  950.    * dump/bootup.
  951.    */
  952.   void
  953. ***************
  954. *** 107,113 ****
  955.   {
  956.       register struct zoneinfo *zp;
  957.       int zonenum;
  958.       gettime(&tt);
  959.   
  960.       dprintf(1, (ddt, "\nns_maint(); now %s", ctimel(tt.tv_sec)));
  961. --- 118,127 ----
  962.   {
  963.       register struct zoneinfo *zp;
  964.       int zonenum;
  965. ! #ifdef MSQL
  966. !     int updatemsql=0, dbupdate=0, lastupdate=0, dbtime=0;
  967. !     dbupdatereload = dbrefresh=0;
  968. ! #endif
  969.       gettime(&tt);
  970.   
  971.       dprintf(1, (ddt, "\nns_maint(); now %s", ctimel(tt.tv_sec)));
  972. ***************
  973. *** 118,124 ****
  974.           if (debug >= 2)
  975.               printzoneinfo(zonenum);
  976.   #endif
  977. !         if (tt.tv_sec >= zp->z_time && zp->z_refresh > 0) {
  978.               switch (zp->z_type) {
  979.   
  980.               case Z_CACHE:
  981. --- 132,147 ----
  982.           if (debug >= 2)
  983.               printzoneinfo(zonenum);
  984.   #endif
  985. ! #ifdef MSQL
  986. ! /* Check to see if there actually is a msql entry in this zone */
  987. !         if (zp->z_dbupdate)
  988. !           updatemsql=msql_update_check(zp); 
  989. !         if ((tt.tv_sec >= zp->z_time && zp->z_refresh > 0 ) || 
  990. !             updatemsql){
  991. ! #else
  992. !          if (tt.tv_sec >= zp->z_time && zp->z_refresh > 0) {
  993. ! #endif
  994.               switch (zp->z_type) {
  995.   
  996.               case Z_CACHE:
  997. ***************
  998. *** 162,169 ****
  999.   #endif /* ALLOW_UPDATES */
  1000.               }
  1001.               gettime(&tt);
  1002. !         }
  1003. !     }
  1004.   #ifdef CLEANCACHE
  1005.       if ((cache_time + cache_interval) <= tt.tv_sec) {
  1006.           if (cache_time)
  1007. --- 185,201 ----
  1008.   #endif /* ALLOW_UPDATES */
  1009.               }
  1010.               gettime(&tt);
  1011. !             }
  1012. ! #ifdef MSQL
  1013. !         dbupdate += updatemsql;
  1014. !         if (lastupdate < zp->z_dblastupdate)
  1015. !           lastupdate = zp->z_dblastupdate;
  1016. !         if (dbrefresh < zp->z_dbrefresh)
  1017. !           dbrefresh = zp->z_dbrefresh;
  1018. ! #endif
  1019. !               
  1020. !           }
  1021.   #ifdef CLEANCACHE
  1022.       if ((cache_time + cache_interval) <= tt.tv_sec) {
  1023.           if (cache_time)
  1024. ***************
  1025. *** 178,183 ****
  1026. --- 210,234 ----
  1027.           stats_time = tt.tv_sec;
  1028.       }
  1029.   #endif
  1030. + #ifdef MSQL
  1031. +     if ((lastupdate + dbrefresh) < tt.tv_sec){
  1032. +       dbupdatereload++;
  1033. +       for (zp = zones, zonenum = 0; 
  1034. +            zp < &zones[nzones]; zp++, zonenum++)
  1035. +         zp->z_dbtime=0;
  1036. +     } else if (!lastupdate)
  1037. +       dbupdate=0;
  1038. +     if (dbupdatereload){
  1039. +       db_reload();
  1040. +       needmaint=0;
  1041. +      }else if (dbupdate){      
  1042. +       for (zp = zones, zonenum = 0; zp < &zones[nzones]; zp++, zonenum++)
  1043. +         if (msql_update_check(zp)) 
  1044. +           (void) db_load(zp->z_source, zp->z_origin, zp, NULL);
  1045. +       needmaint=0;
  1046. +     }        
  1047. + #endif
  1048.       if (!needmaint)
  1049.           sched_maint();
  1050.       dprintf(1, (ddt, "exit ns_maint()\n"));
  1051. ***************
  1052. *** 198,208 ****
  1053.       time_t next_refresh = 0;
  1054.   #endif
  1055.       static time_t next_alarm;
  1056.   
  1057.       for (zp = zones; zp < &zones[nzones]; zp++)
  1058. !         if (zp->z_time != 0 &&
  1059. !             (next_refresh == 0 || next_refresh > zp->z_time))
  1060. !             next_refresh = zp->z_time;
  1061.           /*
  1062.        *  Schedule the next call to ns_maint.
  1063.        *  Don't visit any sooner than maint_interval.
  1064. --- 249,281 ----
  1065.       time_t next_refresh = 0;
  1066.   #endif
  1067.       static time_t next_alarm;
  1068. + #ifdef MSQL
  1069. +      int updatemsql=0;
  1070. + #endif
  1071.   
  1072.       for (zp = zones; zp < &zones[nzones]; zp++)
  1073. !         if (zp->z_time != 0 &&    
  1074. ! #ifdef MSQL
  1075. !             (next_refresh == 0 || next_refresh > zp->z_time) ||
  1076. !             (zp->z_dbupdate && zp->z_dbhost && zp->z_dbname)){
  1077. !           if (zp->z_dbupdate && zp->z_dbhost && zp->z_dbname){
  1078. !             if (updatemsql < zp->z_dbupdate)
  1079. !               updatemsql=zp->z_dbupdate;
  1080. !             gettime(&tt);
  1081. !             next_refresh = tt.tv_sec + updatemsql;
  1082. !             if (dbupdatereload){
  1083. !               dbupdatereload = 0;
  1084. !               zp->z_dblastupdate = tt.tv_sec;
  1085. !             };
  1086. !               } else{
  1087. ! #else
  1088. !             (next_refresh == 0 || next_refresh > zp->z_time)){
  1089. ! #endif
  1090. !             next_refresh = zp->z_time;
  1091. !           }
  1092. ! #ifdef MSQL
  1093. !           }
  1094. ! #endif
  1095.           /*
  1096.        *  Schedule the next call to ns_maint.
  1097.        *  Don't visit any sooner than maint_interval.
  1098. ***************
  1099. *** 220,226 ****
  1100. --- 293,304 ----
  1101.           if (next_refresh < tt.tv_sec)
  1102.               next_refresh = tt.tv_sec;
  1103.           ival.it_value.tv_sec = next_refresh - tt.tv_sec;
  1104. + #ifdef MSQL
  1105. +         if (((long) ival.it_value.tv_sec < maint_interval) 
  1106. +             && !updatemsql)
  1107. + #else
  1108.           if ((long) ival.it_value.tv_sec < maint_interval)
  1109. + #endif
  1110.               ival.it_value.tv_sec = maint_interval;
  1111.           next_alarm = next_refresh;
  1112.           alarm_pending = 1;
  1113. ***************
  1114. *** 978,980 ****
  1115. --- 1056,1059 ----
  1116.           tryxfer();
  1117.       }
  1118.   }
  1119.